﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace FPC.Offer.UI.GeneralProcessor.SkyDriveHand
{
    /// <summary>
    /// AddNetTrayHandler 的摘要说明
    /// </summary>
    public class AddNetTrayHandler : IHttpHandler, IReadOnlySessionState
    {
        FPC.Offer.Service.System_NetTrayTableService Sky = new Service.System_NetTrayTableService();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            var FileName = context.Request["FileName"];
            List<Model.Dropbox_NetTray> c = Sky.Find(w => w.FileName == FileName).ToList();
            if (c.Count() > 0)
            {
                context.Response.Redirect("/SkyDrive/wangpanindex.aspx");

                return;

            }






            string pat = System.AppDomain.CurrentDomain.BaseDirectory + context.Session[FPC.Offer.Common.SystemKeys.COOKIE_USER_UserID_REMEMBER].ToString() + "\\" + FileName;
            //string path = Server.mapPath("") + "\\" + name;


            if (Directory.Exists(pat))
            {
                context.Response.Redirect("/SkyDrive/wangpanindex.aspx");
                return;
            }
            else
            {
                DirectoryInfo folder = Directory.CreateDirectory(pat);
                string time = Convert.ToString(Directory.GetCreationTime(pat));
                string foldername = FileName.Substring(FileName.LastIndexOf("\\") + 1);
                long daxiao = foldername.LongCount();              
                var FilePwd = "1234";
                var FileMemory = "";
                var MemorySum = "200m";
                var NetState = 1;

                Model.Dropbox_NetTray s = new Model.Dropbox_NetTray();

                s.FileName = FileName;
                s.FilePwd = FilePwd;
                s.FileDate = DateTime.Now;
                s.FileMemory = FileMemory;
                s.MemorySum = MemorySum;
                s.NetState = NetState;
                s.NUrl = pat;
                s.FName = context.Session[FPC.Offer.Common.SystemKeys.COOKIE_USER_UserID_REMEMBER].ToString();

                int a = Sky.Add(s);
                if (a > 0)
                {
                    context.Response.Redirect("/SkyDrive/wangpanindex.aspx");
                }
                else
                {

                    context.Response.Write("<script>alert('添加失败');</script>");
                }
            }






        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}